<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8" import="common.*,Dao.*,vo.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<%
request.setCharacterEncoding("utf-8");
User user = (User)session.getAttribute("user");
Md5 md = new Md5();
Userdao dao = new Userdao();
int id = user.getUser_id();
String oldpass = request.getParameter("pass1");
String newpass = request.getParameter("pass3");
String mdoldpass = md.getMD5(oldpass);
String trpass = dao.getpass(id);
if(mdoldpass.equals(trpass)){
	String mdnewpass = md.getMD5(newpass);
	int result = dao.setpass(id, mdnewpass);
	if(result > 0){
		%>
		<script type="text/javascript">
		window.alert("密码修改成功！");
		window.location.href="Login_out.jsp";
		</script>
		<% 
	}else{
		%>
		<script type="text/javascript">
		window.alert("密码修改失败！");
		window.location.href="changepass.jsp";
		</script>
		<% 
	}
}else{
	%>
	<script type="text/javascript">
	window.alert("密码错误！");
	window.location.href="changepass.jsp";
	</script>
	<% 
}


%>
</body>
</html>